home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
btree4.zip
/
BTREE4.DOC
next >
Wrap
Text File
|
1988-01-17
|
26KB
|
661 lines
BTREE4
a Shareware Unit for Turbo Pascal ver. 4.0
for Data and Index file management
Copyright (c) 1988 by W. Lee Passey
Pass-Key Software
119 MacArthur Ave.
Salt Lake City, UT 84115
(801) 486-9239 (voice)
(801) 485-7211 (data)
BTree4 is a separately compiled unit for Turbo Pascal ver. 4.0 from
Borland International, Inc. BTree4 may be linked to a user's source pro-
grams, and will performs all of the same B-tree indexing functions as
Borland's Database Toolbox.
This file contains general information about BTree4, an annotated copy
of the interface segment describing all variables and procedures available
to calling procedures, and licensing and registration information. PLEASE
READ THIS FILE COMPLETELY BEFORE ATTEMPTING TO USE BTREE4.
BTree4 has been designed to be as compatible as possible with Borland's
Database Toolbox, but it is not a modification of Borland's source code;
rather it is a whole new set of procedures and functions using a compatible
calling interface, but a wholly different memory storage technique. BTree4
does not require any pre-defined constants or initializaton sequence, as all
data storage, including the index page stack, is created as needed on the
heap.
For maximum flexibility, the BTree4 routines will not halt the program
for any IO or heap full errors. If an error is detected, the global boolean
variable 'OK' is set to false, and the global integer variable 'IOError' is
set equal to the IO error code. If the error was caused by the unavail-
ability of heap memory, 'IOError' will be set to -1.
Disk IO errors must be resolved by the programmer, however memory
allocation errors can usually be resolved by the use of the procedure
'CheckMem' in conjunction with the global variable 'MaxPageMem.'
'MaxPageMem' should be set by the programmer to the maximum amount of heap
memory which will be allocated for the index page stack. If the page stack
attempts to exceed this amount of allocated memory, little used pages will
be discarded from memory until the page stack is again under the limit. The
program expects that the amount of memory available will never be less than
the value stored in 'MinPageMem', and the stack size will never be decreased
to less than that value; thus, 'MaxPageMem' should always be larger than
'MinPageMem.'
Both 'MaxPageMem' and 'MinPageMem' can be dynamically assigned values
at any time during the operation of the program. If more dynamic memory is
needed, the page stack can be reduced in size by reducing the value of
'MaxPageMem' (and 'MinPageMem', if necessary) and then calling CheckMem with
a zero parameter. The only restriction is that 'MinPageMem' must always be
large enough to hold one page from each level of the tree, plus one extra
page.
In addition to the page stack, each open data file and index file
allocates for itself an IO buffer equal in size to the file's record length,
and each index file allocates an extra page buffer which is the same size.
These buffers are de-allocated only by closing the associated file. The
record length for index files is equal to 5 + (number of keys per page X
(key length + 9)).
What follows is a copy of the BTree4 interface section, with each
procedure and significant variable annotated as to its function and use.
{$I-,V-}
unit btree4; { VERSION 1.0 }
{ Copyright (c) 1988 by W. Lee Passey }
interface
type
MaxString = string[255];
bufarray = array [1..80] of byte;
Str80 = string[80];
PagePtr = ^PageHeader;
KeyListPtr = ^KeyList;
DataFile = record
case byte of
0 : (F : file);
1 : (Handle,
Mode,
RecSize : word;
Private : array [1..26] of byte; { reserved by TP4 }
FirstFree, { the first available record in the file }
NumberFree : longint; { the number of records deleted and
therefore available for use }
RecLength : word; { the length of records in this file }
KeysPerPage, { if an index file, the maximum number
of keys which may be put on a page }
KeyLength : byte; { if an index file, the maximum
length of a key }
FirstPage : longint; { if an index file, the number of the
record which is the root page }
FileName : array [1..80] of char;
Buffer : ^BufArray);{ pointer to a buffer on the heap,
used with this file, whose size is
identical to the record length }
end;
IndexFile = record
DF : DataFile;
RootPage : PagePtr; { a pointer to the root page, if it
is in memory }
KeySize, { the size of a key record, on the
heap, for keys in this file }
ItemSize : word; { the size of a key, its reference
and record pointer, in this file }
SavePage : PagePtr;
SaveKey : KeyListPtr;
SaveRec : longint;
PageBuffer: ^BufArray; { pointer to a buffer on the heap,
used with this file, whose size is
identical to the record length, and
which is used for packing and
unpacking pages to and from the disk
and memory. }
end;
(* Like Borland's Database Toolbook, each file use by BTree4 must be
declared either as a DataFile or an IndexFile. *)
PageHeader = record
NextPage, { these two pointers link the pages }
PrevPage, { into a two-way linked list in memory
each time a page is used it is placed
back at the head of this list }
ParentPage, { a pointer to this page's parent page
which should be in memory }
GreaterPage : PagePtr; { a pointer to a page on a lower level
containing keys greater than all
keys on this page, if in memory }
GreaterRec, { the disk record number of the page
which goes in GreaterPage }
RecNum : longint; { the disk record number of this page }
FilePtr : ^IndexFile; { points to the file variable of the
file which this page comes from }
ParentKey, { the key record from the parent page
which contains the key which is one
greater than all the keys on this
page. if this pointer is nil, you
must go up another page; if this is